package com.example.mybatis.my.shop.service.impl;

import com.example.mybatis.my.shop.entity.TbUser;
import com.example.mybatis.my.shop.mapper.TbUserMapper;
import com.example.mybatis.my.shop.service.TbUserService;
import com.example.mybatis.my.shop.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Map;

public class TbUserServiceImpl implements TbUserService {

    SqlSession sqlSession = MybatisUtils.getSqlSession();
    TbUserMapper tbUserMapper = sqlSession.getMapper(TbUserMapper.class);

    @Override
    public TbUser selectByEmail(String email) {
        return tbUserMapper.selectByEmail(email);
    }

    @Override
    public List<TbUser> selectTbUsers() {
        return tbUserMapper.selectTbUsers();
    }

    @Override
    public int insertUser(TbUser user) {
        int result = tbUserMapper.insertUser(user);
        sqlSession.commit();
        return result;
    }

    @Override
    public Boolean deleteById(Long id) {
        Boolean aBoolean = tbUserMapper.deleteById(id);
        sqlSession.commit();
        return aBoolean;
    }

    @Override
    public TbUser findById(Long id) {
        return tbUserMapper.findById(id);
    }

    @Override
    public int updateUser(TbUser user) {
        int result = tbUserMapper.updateUser(user);
        sqlSession.commit();
        return result;
    }

    @Override
    public List<TbUser> searchByTbUser(Map<String, String> map) {
        return tbUserMapper.searchByTbUser(map);
    }

    @Override
    public int deleteAllById(String[] ids) {
        int result = tbUserMapper.deleteAllById(ids);
        sqlSession.commit();
        return result;
    }


}
